package it.heima.xmy.Demo01;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/*请按以下要求编写程序：
1. 定义一个学员类，有以下

2. 定义main()方法，定义一个存储Student的集合，并初始化一些数据：

3. 定义一个字符输出缓冲流BufferedWriter对象，将学员信息写入到”Task2.txt”中，
每个学员信息占一行，每个字段之间用,符号隔开，例如：

   迪丽热巴,女,18,99
   古力娜扎,女,19,98
   周杰伦,男,20,88
   蔡徐坤,男,19,78
*/
public class IOTest04 {
    public static void main(String[] args) throws IOException {
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("迪丽热巴", "女", 18, 99));
        stuList.add(new Student("古力娜扎", "女", 19, 98));
        stuList.add(new Student("周杰伦", "男", 20, 88));
        stuList.add(new Student("蔡徐坤", "男", 19, 78));
        BufferedWriter bw = new BufferedWriter(new FileWriter("F:\\task2.txt"));
        for (int i = 0; i < stuList.size(); i++) {
            String name = stuList.get(i).getName();
            String sex = stuList.get(i).getSex();
            int age = stuList.get(i).getAge();
            double score = stuList.get(i).getScore();
            bw.write(new String(name + "," + sex + "," + age + "," + score));
            bw.newLine();
        }
        bw.close();
    }
}

